package com.memoir.jpa.controller;

import com.memoir.jpa.model.TodoDto;
import com.memoir.jpa.service.TodoJseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * 自定义实现复杂单表查询
 *
 * @author ldm
 * @since 2017-10-22
 */
@RestController
@RequestMapping("/jse")
public class TodoJseController {

    //public Object findOne(Specification spec)
    //public List findAll(Specification spec) {
    //public Page findAll(Specification spec, Pageable pageable) {
    //public List findAll(Specification spec, Sort sort) {
    //public long count(Specification spec) {

    @Autowired
    private TodoJseService todoJseService;

    //?page=0&size=4&sort=id,asc&sort=createTime,desc  pageable的真实类对象为pageRequest
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public Page<TodoDto> findAll(@PageableDefault(value = 10,sort = {"id"},direction = Sort.Direction.ASC) Pageable pageable){

        return todoJseService.findAll(pageable);
    }
}